package pers.zh.parking.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.zh.parking.dao.CarMapper;
import pers.zh.parking.po.Car;
import pers.zh.parking.po.CarExample;

import java.util.List;

@Service
public class CarService implements ICarService {

    @Autowired
    CarMapper carMapper;

    @Override
    public List<Car> getAllCars() {
        CarExample carExample = new CarExample();
        carExample.setOrderByClause("car_id desc");
        return carMapper.selectByExample(carExample);
    }

    @Override
    public List<Car> getCars(int userId) {
        return carMapper.selectByUId(userId);
    }

    @Override
    public boolean addCar(Car car) {
        return carMapper.insertSelective(car) > 0;
    }

    @Override
    public boolean update(Car car) {
        return carMapper.updateByPrimaryKeySelective(car) > 0;
    }

    @Override
    public boolean existCarNo(String carNo) {
        return carMapper.existCarNo(carNo) > 0;
    }

    @Override
    public boolean batchDel(List<Car> cars) {
        return carMapper.batchDel(cars) > 0;
    }
}
